<?php
/**
 * 《我的产品》实现类
 *
 * @author 孙晓晔
 * @version $Id: Barcode.class.php 1035 2010-03-26 05:24:59Z sunxy $
 */
require_once(dirname(__FILE__) . '/MoldUtil.class.php');

class Barcode extends MoldUtil {

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
	}

	function pretreat($controller) {
		parent::pretreat($controller);
	}

	/**
	 *
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function find($controller, $request) {
		$this->pretreat($controller);

		$controller->display($request, 'barcode/find');
		return true;
	}

	/**
	 *
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function findPost($controller, $request) {
		$this->findPara($controller, $request);

		$barcode_s = $request['barcode_s'];
		if (empty($barcode_s)) {
			$controller->assign("msg", "条码不能为空，请重新操作");
			$controller->display($request, 'info');
			return false;
		}

		$aa = explode('.', $barcode_s);

		$aa = $aa[0];

		if ($aa == '1') {
			require_once 'Plan.class.php';
			$bar = new Plan();
			return $bar->_bar($controller, $request);
		}

		if ($aa == '2') {
			require_once 'Produce.class.php';
			$bar = new Produce();
			return $bar->_bar($controller, $request);
		}
	}

	/**
	 *
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function plan($controller, $request) {
		$id = $request['id'];
		clean($this->tbl . "_id_" . $id);

		$status = $request['status'];

		$db = newdb($this->dsn);
		$fmt = "UPDATE %s SET status = '%s', modifytime = now() WHERE id = '%s'";
		$sql = sprintf($fmt, Constant::tbl_mold_plan, $status, $id);
		// debug($sql);
		$db->query($sql);
		
		$controller->assign('baseLink', $this->doGet($request, 'findPost'));

		$this->findPost($controller, $request);
		return true;
	}

	/**
	 *
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function produce($controller, $request) {
		$id = $request['id'];
		clean($this->tbl . "_id_" . $id);

		$emp = $request['emp'];
		if (empty($emp)) {
			$emp = $_SESSION['id'];
		}

		$status = $request['status'];

		$db = newdb($this->dsn);
		$fmt = "UPDATE %s SET quality = '%s', status = '%s', modifytime = now() WHERE id = '%s'";
		$sql = sprintf($fmt, Constant::tbl_mold_produce, $emp, $status, $id);
		// debug($sql);
		$db->query($sql);
		
		$controller->assign('baseLink', $this->doGet($request, 'findPost'));

		$this->findPost($controller, $request);
		return true;
	}

}
?>